Hi everyone, I have a column with ID in string and a attribute "Number" in Interger. The problem is, there a few duplicated values in "Number" and i have to find and display them. So any kind of help is really appreciated. Thanks, Jonny Jonny Tim - Fri Oct 12 14:02:41 EDT 2018 |
Re: Finding Duplicate Using Skip List Hi Jonny, perhaps one skip list is enough key: integer (related number), data: string (ID). You can walk through all objects (for o in m, or for o in entire m), and ask sth like
int relNumOfThisObject = o."related number"
string IDOfThisObject = o."ID"
string IDOfThatObject = ""
if (find (skRelNum, relNumOfThisObject, IDOfThatObject)){
print "found a duplicate. " (relNumOfThisObject) " appears in " IDOfThatObject " and " IDOfThisObject "\n"
} else {
put (sRelNum, relNumOfThisObject, IDOfThisObject)
}
|
Re: Finding Duplicate Using Skip List Mike.Scharnow - Fri Oct 12 15:57:40 EDT 2018 Hi Jonny, perhaps one skip list is enough key: integer (related number), data: string (ID). You can walk through all objects (for o in m, or for o in entire m), and ask sth like
int relNumOfThisObject = o."related number"
string IDOfThisObject = o."ID"
string IDOfThatObject = ""
if (find (skRelNum, relNumOfThisObject, IDOfThatObject)){
print "found a duplicate. " (relNumOfThisObject) " appears in " IDOfThatObject " and " IDOfThisObject "\n"
} else {
put (sRelNum, relNumOfThisObject, IDOfThisObject)
}
Hi Mike, Firstly, thank you for your idea. To make it clear, i have written the entire code here. Can you please take a look and correct me if I'm wrong:
Skip fGetSelectedObjects(Module in_mod)
{
Skip skpObjects = create() // Return KEY and DATA both 'Object'
if (null in_mod) return(skpObjects)
Object oCurr = current, o
for o in entire (in_mod) do
{ if (isSelected(o) or o == oCurr)
{
put(skpObjects, o, identifier(o))
}
}
return(skpObjects)
}
Skip skRelNum = fGetSelectedObjects(current Module)
Object o
for o in current Module do {
if(isSelected(o)){
int relNumOfThisObject = o."related number"
string IDOfThisObject = identifier(o)
string IDOfThatObject = ""
if (find (skRelNum, relNumOfThisObject, IDOfThatObject)){
print "found a duplicate. " (relNumOfThisObject) " appears in " IDOfThatObject " and " IDOfThisObject "\n"
} else {
put (sRelNum, relNumOfThisObject, IDOfThisObject)
print "Every thing OK"
}
}
}
|
Re: Finding Duplicate Using Skip List Jonny Tim - Sat Oct 13 04:21:54 EDT 2018 Hi Mike, Firstly, thank you for your idea. To make it clear, i have written the entire code here. Can you please take a look and correct me if I'm wrong:
Skip fGetSelectedObjects(Module in_mod)
{
Skip skpObjects = create() // Return KEY and DATA both 'Object'
if (null in_mod) return(skpObjects)
Object oCurr = current, o
for o in entire (in_mod) do
{ if (isSelected(o) or o == oCurr)
{
put(skpObjects, o, identifier(o))
}
}
return(skpObjects)
}
Skip skRelNum = fGetSelectedObjects(current Module)
Object o
for o in current Module do {
if(isSelected(o)){
int relNumOfThisObject = o."related number"
string IDOfThisObject = identifier(o)
string IDOfThatObject = ""
if (find (skRelNum, relNumOfThisObject, IDOfThatObject)){
print "found a duplicate. " (relNumOfThisObject) " appears in " IDOfThatObject " and " IDOfThisObject "\n"
} else {
put (sRelNum, relNumOfThisObject, IDOfThisObject)
print "Every thing OK"
}
}
}
Hi Jonny, First, I don't understand your general intention of the script, escecially why and how you use isSelected. Objects are "selected" when you press on two objects with shift down (or on one object twice), and they become "red". If it is your intention only to check these objects where one of them contains a duplicate in relation to the other objects of your selection, "isSelected" is correct. If instead of this you want to check all objects that are currently filtered, you should use the "for o in m" loop, which only loops through all filtered objects as opposed to "for o in entire m" which loops through every object contained in the module. Perhaps you want to traverse every object and just filter out the deleted objects? This would make a loop "for o in entire m do { if isDeleted(o) then continue...}" Then, it seems we have a misunderstanding about the role "related number" and "identifier" play, the way the script is written now, is inconsistent. I thought that the script I provided was complete if you just added a surrounding
Skip skRelNum=create()
Object o
for o in m do {
.. here some if statement to determine if the object shall be evaluated
.... here the script from my first post
}
delete skRelNum
I am now confused about your second loop. Perhaps you can write down a small example on how a module looks like, which attributes they contain (especially absolute number and related number), which objects shall be traversed in your script and what exactly you want to compare, what is a duplicate exactly?
Regards, |
Re: Finding Duplicate Using Skip List Mike.Scharnow - Sun Oct 14 08:43:34 EDT 2018 Hi Jonny, First, I don't understand your general intention of the script, escecially why and how you use isSelected. Objects are "selected" when you press on two objects with shift down (or on one object twice), and they become "red". If it is your intention only to check these objects where one of them contains a duplicate in relation to the other objects of your selection, "isSelected" is correct. If instead of this you want to check all objects that are currently filtered, you should use the "for o in m" loop, which only loops through all filtered objects as opposed to "for o in entire m" which loops through every object contained in the module. Perhaps you want to traverse every object and just filter out the deleted objects? This would make a loop "for o in entire m do { if isDeleted(o) then continue...}" Then, it seems we have a misunderstanding about the role "related number" and "identifier" play, the way the script is written now, is inconsistent. I thought that the script I provided was complete if you just added a surrounding
Skip skRelNum=create()
Object o
for o in m do {
.. here some if statement to determine if the object shall be evaluated
.... here the script from my first post
}
delete skRelNum
I am now confused about your second loop. Perhaps you can write down a small example on how a module looks like, which attributes they contain (especially absolute number and related number), which objects shall be traversed in your script and what exactly you want to compare, what is a duplicate exactly?
Regards, Hi Mike, I'm really sorry for the inconvenient. I forgot the requirement of this task. Here is my example of my task. The "red" columns are the selected columns, which I want to check duplicates. It means that the ID, which I want to take, is ABC1245 and ASC1234, because they have the duplicate number "1". Moreover, I don't understand the "m" in for loop. What is the meaning of "m"? Can you please explain more?
Thanks in advance
|
Re: Finding Duplicate Using Skip List Jonny Tim - Sun Oct 14 09:48:03 EDT 2018 Hi Mike, I'm really sorry for the inconvenient. I forgot the requirement of this task. Here is my example of my task. The "red" columns are the selected columns, which I want to check duplicates. It means that the ID, which I want to take, is ABC1245 and ASC1234, because they have the duplicate number "1". Moreover, I don't understand the "m" in for loop. What is the meaning of "m"? Can you please explain more?
Thanks in advance
Hi Jonny, "m" is a variable name that is used very often for variables of type Module, especially in the DXL manual, As the "current Module" can change very easily during a script, espeically if a GUI is involved or when other modules are opened by the script, it is often advisable to set a Module variable right at the beginning of a script and use it from there on. But you are completely right, in the source code extracts that I posted, the variable was not set, sorry for the confusion.
So, with this requirement, as I imagined, in my point of opinion there is really no need to have a second skip list. It should suffice if the script works like this: Skip of related numbers is empty for o in m : ABC123: not selected, next object ABC1245: is "1" already in the list of related Numbers? No (list is empty). Remember that related number "1" is used in ABC1245 ABC1123: is "2" already in the list of related Numbers? No. Remember that related number "2" is used in ABC1123 ASC1234: is "1" already in the list of related Numbers? Yes! So, a) print the remembered ID ABC1245 and b) print the current ID ASC1234 AMN1245: is "5" already in the list of related Numbers? No. Remember that related number "5" is used in AMN1245 AMD134: not selected, next object So, the complete code would be
Skip skRelNum=create()
Module m = current
Object o
for o in m do {
if (!isSelected(o)) continue
int relNumOfThisObject = o."related number"
string IDOfThisObject = identifier o
string IDOfThatObject = ""
if (find (skRelNum, relNumOfThisObject, IDOfThatObject)){
print "found a duplicate. " (relNumOfThisObject) " appears in " IDOfThatObject " and " IDOfThisObject "\n"
} else {
put (skRelNum, relNumOfThisObject, IDOfThisObject)
}
}
delete skRelNum
Edit: Script corrections: a) typo: sRelNum → skRelNum b) with "ID" you meant not an attribute "ID" but the "identifier" of the object. |
Re: Finding Duplicate Using Skip List Mike.Scharnow - Mon Oct 15 01:56:38 EDT 2018 Hi Jonny, "m" is a variable name that is used very often for variables of type Module, especially in the DXL manual, As the "current Module" can change very easily during a script, espeically if a GUI is involved or when other modules are opened by the script, it is often advisable to set a Module variable right at the beginning of a script and use it from there on. But you are completely right, in the source code extracts that I posted, the variable was not set, sorry for the confusion.
So, with this requirement, as I imagined, in my point of opinion there is really no need to have a second skip list. It should suffice if the script works like this: Skip of related numbers is empty for o in m : ABC123: not selected, next object ABC1245: is "1" already in the list of related Numbers? No (list is empty). Remember that related number "1" is used in ABC1245 ABC1123: is "2" already in the list of related Numbers? No. Remember that related number "2" is used in ABC1123 ASC1234: is "1" already in the list of related Numbers? Yes! So, a) print the remembered ID ABC1245 and b) print the current ID ASC1234 AMN1245: is "5" already in the list of related Numbers? No. Remember that related number "5" is used in AMN1245 AMD134: not selected, next object So, the complete code would be
Skip skRelNum=create()
Module m = current
Object o
for o in m do {
if (!isSelected(o)) continue
int relNumOfThisObject = o."related number"
string IDOfThisObject = identifier o
string IDOfThatObject = ""
if (find (skRelNum, relNumOfThisObject, IDOfThatObject)){
print "found a duplicate. " (relNumOfThisObject) " appears in " IDOfThatObject " and " IDOfThisObject "\n"
} else {
put (skRelNum, relNumOfThisObject, IDOfThisObject)
}
}
delete skRelNum
Edit: Script corrections: a) typo: sRelNum → skRelNum b) with "ID" you meant not an attribute "ID" but the "identifier" of the object. It worked very well. Thanks again for your help |